package cn.nbt.busManage.model.dto;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.nbt.busManage.model.entity.Bus;
import cn.nbt.busManage.model.entity.Driver;
import cn.nbt.busManage.model.entity.Schedule;
import cn.nbt.busManage.model.vo.DriverVo;
import cn.nbt.busManage.model.vo.ScheduleVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

@Data
public class DriverDto {
    private List<ScheduleDto> schedules  = new ArrayList<>(); //司机上班表
    private Integer id;
    private String driverName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime birthday;
    private String address;
    private String cell;

    public DriverDto(DriverVo driverVo){
        this.id = driverVo.getId();
        this.driverName=driverVo.getDriverName();
        this.birthday=driverVo.getBirthday();
        this.address=driverVo.getAddress();
        this.cell=driverVo.getCell();
        if(driverVo.getSchedules()!=null){
            ArrayList<ScheduleDto> scheduleDtos = new ArrayList<>();
            for (ScheduleVo scheduleVo : driverVo.getSchedules()){
                ScheduleDto scheduleDto = new ScheduleDto(scheduleVo);
                scheduleDtos.add(scheduleDto);
            }
            this.schedules=scheduleDtos;
        }else {
            this.schedules = new ArrayList<>();
        }
    }

    public DriverDto(Driver driver){
        this.id = driver.getId();
        this.driverName=driver.getDriverName();
        this.birthday=driver.getBirthday();
        this.address=driver.getAddress();
        this.cell=driver.getCell();
        ArrayList<ScheduleDto> scheduleDtos = new ArrayList<>();
        for (Schedule schedule : driver.getSchedules()){
            ScheduleDto scheduleDto = new ScheduleDto(schedule);
            scheduleDtos.add(scheduleDto);
        }
        this.schedules=scheduleDtos;
    }
}
